<?php

/**
 * mainmenu actions.
 *
 * @package    eveladder
 * @subpackage mainmenu
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class sidebarComponents extends sfComponents
{
  /**
   * Executes index action
   *
   */
  public function executeDefault()
  {
  	/* top n */
  	$c = new Criteria() ;
  	$c->addDescendingOrderByColumn(PlayerPeer::POINTS) ;
  	$c->setLimit(sfConfig::get('app_pager_sidebar_tops')) ;
  	$this->tops = PlayerPeer::doSelect($c) ;

  	/* top ratio */
		$sql = "SELECT u.id, u.username, p.nb_win / p.nb_challenge as ratio
						FROM sf_guard_user u, player p 
						WHERE u.id = p.user_id 
						ORDER BY ratio DESC " ;
						
		$con = Propel::getConnection();
		$stmt = $con->prepareStatement($sql);
  	$stmt->setLimit(sfConfig::get('app_pager_sidebar_ratio')) ;
		$this->ratios = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);

  	/* top scorer */
  	$c = new Criteria() ;
  	$c->addDescendingOrderByColumn(PlayerPeer::NB_WIN) ;
  	$c->setLimit(sfConfig::get('app_pager_sidebar_winner')) ;
  	$this->scorers = PlayerPeer::doSelect($c) ;

  	/* top looser */
  	$c = new Criteria() ;
  	$c->addDescendingOrderByColumn(PlayerPeer::NB_LOSS) ;
  	$c->setLimit(sfConfig::get('app_pager_sidebar_looser')) ;
  	$this->loosers = PlayerPeer::doSelect($c) ;
  }
}
